package com.warrior.superdata.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Charsets;
import lombok.Data;

import java.io.*;

@Data
public class JsonHelper {
    private String properties_File_Path;

    public JsonHelper(String properties_File_Path) {
        this.properties_File_Path = properties_File_Path;
    }

    public JSONObject getJson(){
        try {
            InputStream inputStream = this.getClass()
                    .getResourceAsStream(getProperties_File_Path());
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            String resultStr = new String(bytes, Charsets.UTF_8);
            return JSONObject.parseObject(resultStr);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public JSONArray getJsonArr(){
        try {
            InputStream inputStream = this.getClass()
                    .getResourceAsStream(getProperties_File_Path());
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            String resultStr = new String(bytes, Charsets.UTF_8);
            return JSONArray.parseArray(resultStr);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
